def midi_constrain( n ):
    n = int( n )
    if n< 0:
        return 0
    if n > 127:
        return 127
    return n      